


<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layuiAdmin 网站用户 iframe 框</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../layui/css/layui.css" media="all">
</head>
<style>
  .layui-form-select{
    width:200px
  }
  .layui-select-title{
    width:200px
  }
  .layui-input{
    width: 200px;
  }
  
</style>
<body>

  <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">评论内容</label>
      <div class="layui-input-inline">
        <textarea name="content" lay-verify="required" autocomplete="off" class="layui-textarea" style="width: 400px; height: 150px;" ></textarea>
      </div>
    </div> 
    
  </div>
  <script src="./JS/utils/request.js"></script>
  <script src="./JS/utils/auth.js"></script>
  <script src="../layui/layui.all.js"></script>  
  <script>
layui.use(['form', 'jquery','upload'], function(){
            let form = layui.form;
            let $ = layui.$;
            let upload = layui.upload

            // 暴露初始化方法供父页面调用用于编辑信息时的数据回显
            window.initFormData = function(data){
              // 填充表单数据
              form.val('layuiadmin-form-useradmin', {
                "content": data.content,  
              });
              // 重新渲染表单
              form.render();
            };

        //     保存更改后的表单数据
        // 定义提交方法供父页面调用
        window.updateForm = function(callback) {
          const urlParams = new URLSearchParams(window.location.search);
          console.log(urlParams)
          const commentId = urlParams.get('commentId');
          console.log(commentId)
          // 表单验证
          form.verify();

          // 获取表单数据
          let formData = {
            content: $('textarea[name="content"]').val(),
            commentId:commentId
          };

          console.log(formData);

          // 发送AJAX请求
          $.ajax({
            url: '/comments/update',
            method: 'PUT',
            contentType: 'application/json',
            data: JSON.stringify(formData),
            headers:{
              'Authorization':localStorage.getItem('token')
    },
            success: function(res){
              console.log(res)
              if(res.code === 0){
                callback(true);
              } else {
                layer.msg(res.msg || '更新失败');
                callback(false);
              }
            },
            error: function(xhr){
              layer.msg('请求失败:' + xhr.statusText);
              callback(false);
            }
          });
        };


        });
  </script>
</body>
</html>